package top.lingkang.finalsessionsolon.test02;

import org.noear.solon.Solon;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.MethodType;
import org.noear.solon.core.handle.SessionState;

/**
 * @author lingkang
 * Created by 2024/5/9
 */
@Controller
public class WebApp {
    public static void main(String[] args) {
        Solon.start(WebApp.class, args);
    }

    @Mapping(value = "/", method = MethodType.GET)
    public Object index(Context context) {
        System.out.println(context.path());
        System.out.println(context.sessionState().getClass());
        return "ok";
    }

    @Mapping("/session")
    public Object session(Context context) {
        SessionState session = context.sessionState();
        Object a = session.sessionGet("a");
        if (a == null) {
            session.sessionSet("a", System.currentTimeMillis());
        }
        System.out.println(a);
        return "ok";
    }
}
